#include "settingsdialog.h"

#include <QtGui>

SettingsDialog::SettingsDialog(QString _path, int _minQueryLength, int _numberOfSuggestions, QWidget *parent) :
	QDialog(parent)
{

	QLabel *pathText = new QLabel(tr("Path to dictionary database files:"));
	path = new QLineEdit();
	path->setText(_path);

	QLabel *queryLengthText = new QLabel(tr("Display suggestions after entering"));
	minQueryLength = new QSpinBox();
	minQueryLength->setMinimum(1);
	minQueryLength->setMaximum(100);
	minQueryLength->setSuffix(" " + tr("characters"));
	minQueryLength->setValue(_minQueryLength);

	QLabel *numberOfSuggestionsText = new QLabel(tr("Number of suggestions:"));
	numberOfSuggestions = new QSpinBox();
	numberOfSuggestions->setMinimum(1);
	numberOfSuggestions->setMaximum(1000);
	numberOfSuggestions->setValue(_numberOfSuggestions);

	QLabel *note = new QLabel(tr("Note: New path is only applied after restart."));
	note->setWordWrap(true);
	note->setStyleSheet("QLabel{ color: grey }");

	QHBoxLayout *hl1 = new QHBoxLayout();
	hl1->addWidget(minQueryLength);
//	hl1->addWidget(unitText);
	hl1->addStretch();

	QHBoxLayout *hl2 = new QHBoxLayout();
	hl2->addWidget(numberOfSuggestions);
	hl2->addStretch();

	QVBoxLayout *vl1 = new QVBoxLayout();
	vl1->addWidget(pathText);
	vl1->addWidget(path);
	vl1->addSpacing(10);
	vl1->addWidget(queryLengthText);
	vl1->addLayout(hl1);
	vl1->addSpacing(10);
	vl1->addWidget(numberOfSuggestionsText);
	vl1->addLayout(hl2);
	vl1->addStretch();
	vl1->addWidget(note);

	setLayout(vl1);

	QAction *cancelButton = new QAction(tr("Cancel"), this);
	cancelButton->setSoftKeyRole(QAction::NegativeSoftKey);
	connect(cancelButton, SIGNAL(triggered()), this, SLOT(reject()));
	addAction(cancelButton);

	QAction *applyButton = new QAction(tr("Apply"), this);
	applyButton->setSoftKeyRole(QAction::PositiveSoftKey);
	connect(applyButton, SIGNAL(triggered()), this, SLOT(accept()));
	addAction(applyButton);

	setStyleSheet("QLabel { font-size: 20px }");
	setWindowState(Qt::WindowMaximized);
}
